<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>微信支付</title>
    <link href="css/weui.min.css" rel="stylesheet">
    <link href="css/example.css" rel="stylesheet">
</head>
<body ontouchstart>
    <div class="page__hd">
        <h1 class="page__title">
            微信支付
        </h1>
        <p class="page__desc">测试总入口</p>
    </div>
    <div class="page__bd page__bd_spacing">
        <a href="javascript:;" id="unifiedOrder" class="weui-btn weui-btn_primary">统一下单接口测试</a>
        <a href="/wxpay/pages/orderQuery.html" id="orderQuery" class="weui-btn weui-btn_primary">查询订单接口测试</a>
        <a href="/wxpay/pages/closeOrder.html" id="closeOrder" class="weui-btn weui-btn_primary">关闭订单接口测试</a>
        <a href="/wxpay/pages/refund.html" id="refund" class="weui-btn weui-btn_primary">申请退款接口测试</a>
        <a href="/wxpay/pages/refundQuery.html" id="refundQuery" class="weui-btn weui-btn_primary">退款查询接口测试</a>
        <a href="/wxpay/pages/downloadBill.html" id="downloadBill" class="weui-btn weui-btn_primary">下载对账单接口测试</a>
    </div>
    <div class="page__ft"></div>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script>
        var openid = "";
        // 用code换取openid
        var code = getCode();
        if(code != "")
            $.ajax({
                url: "/wxpay/index/getOpenId.do",
                dataType:'json',
                data: {code : code},
                type: "POST",
                success:function(data){
                    if(data.status == "success") {
                        openid = data.openid;
                    } else {
                        alert(data.msg);
                    }
                },
                error:function () {
                    alert("error");
                }
            });
        else
            alert("code为空，不能获取openid");

        $("#unifiedOrder").click(function () {
            window.location.href="/wxpay/pages/unifiedOrder.html?openid=" + openid;
        });

        function getCode() {
            var url = location.search; // 获取url中"?"符后的字串
            var code = "";
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                if (str.indexOf("&") != -1) {
                    var params = str.split("&");
                    var param = params[0].split("=");
                    code = param[1];
                } else {
                    var param = str.split("=");
                    code = param[1];
                }
            }
            return code;
        }
    </script>
</body>
</html>